import { AirApi } from '../../airpower/config/AirApi'
import { IJson } from '../../airpower/interface/IJson'
import { AppConfig } from '../../config/AppConfig'
import { UserEntity } from '../../model/user/UserEntity'

Page({
  data: {
    currentUser: new UserEntity(),
    tabbarIndex: 0,
    tabbar: {
      color: '#666',
      selectedColor: '#48af6e',
      list: [{
        pagePath: '/view/tabbar/index',
        iconPath: '/assets/images/tabbar/tabbar-home.png',
        selectedIconPath: '/assets/images/tabbar/tabbar-home-active.png',
        text: '工作台',
      }, {
        pagePath: '/view/tabbar/index2',
        iconPath: '/assets/images/tabbar/tabbar-mine.png',
        selectedIconPath: '/assets/images/tabbar/tabbar-mine-active.png',
        text: '我的',
      }],
    },
  },
  async onShow() {
    await AppConfig.getCurrentUserInfo()
    this.setData({
      currentUser: AppConfig.currentUser,
    })
  },
  onPullDownRefresh() {
    AirApi.stopPullDownRefresh()
  },
  onGoToProfile() {
    AirApi.navigateTo('../common/profile/index')
  },
  changeTab(e: IJson) {
    console.log(`tab index ${e.detail}`)
    this.setData({
      tabbarIndex: e.detail,
    })
  },
  async onScanQrcode() {
    const res = await wx.scanCode({
      onlyFromCamera: true,
      scanType: ['qrCode'],
    })
    console.log(res.result)
    const dialog = await wx.showModal({
      title: '扫码结果',
      content: res.result,
      confirmText: '复制结果',
    })
    if (dialog.confirm) {
      AirApi.setClipboardData(res.result)
    }
  },
})
